/*
 * Created by Administrator on 2017/3/31.
 */
var Collapse = require('../../../../src/libs/collapse').Collapse;
var Panel = require('../../../../src/libs/collapse').Panel;
var SideBar = React.createClass({
    getDefaultProps: function() {
        return{

        }
    },
    getInitialState: function () {
        return{
            sideBarItem : this.props.sideBarItem
        }
    },
    componentDidMount:function(){

    },
    render: function () {
        var defaultkey = 0;
        var sidebarlist = this.state.sideBarItem.sideBarList;
        for(var i = 0; i < sidebarlist.length; i++){
            for(var j = 0; j < sidebarlist[i].itemChildList.length; j++){
                if(sidebarlist[i].itemChildList[j].current){
                    defaultkey = i;
                    break;
                }
            }
        }

        var collapseSettings = {
            defaultKey: defaultkey,
            afterCallBack : function(){
                console.log("回调");
            }
        };
        var panelSettings = {
            arrow : {
                style : {
                    top: "6px",
                    left: "130px"
                },
                openContent : "<i class='icon-sanjiaoxing iconfont'></i>",
                closeContent : "<i class='icon-sanjiaoxing2 iconfont'></i>"
            },
            headerCanClick: true,
            arrowCanClick: true
        };
        return (
            <div className="sub-nav">
                <Collapse accordion  {...collapseSettings}>
                    {
                        this.state.sideBarItem.sideBarList.map(function(item,index){
                            return (
                                <Panel title={item.itemName} key={index} {...panelSettings}>
                                    <ul>
                                        {
                                            item.itemChildList.map(function(itm,idx){
                                                return (
                                                    <li className={itm.current?"current":""}><a href={itm.childUrl}>{itm.childName}</a></li>
                                                )
                                            })
                                        }
                                    </ul>
                                </Panel>
                            )
                        })
                    }
                </Collapse>
            </div>
        )
    }
})

module.exports = SideBar;